<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="newlist">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="dosubmit">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getlists } from '@/api/settings'
import { getuserimg } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    curId: {
      required: true,
      type: String
    }
  },
  data() {
    return {
      list: [],
      newlist: []
    }
  },
  created() {
    this.getmenus()
    this.getquanxian()
  },
  methods: {
    dosubmit() {
      this.submit()
      this.$emit('success', '成功')
    },
    async submit() {
      await assignRoles({ id: this.curId, roleIds: this.newlist })
    },
    async getquanxian() {
      const { data: res } = await getuserimg(this.curId)
      console.log(res)
      this.newlist = res.roleIds
    },
    closeDialog() {
    },
    async getmenus() {
      const { data: res } = await getlists({ page: 1, size: 100 })
      console.log(res)
      this.list = res.rows
    }
  }
}
</script>
